package com.niiwoo.civet.user.service.duboo;

import com.alibaba.dubbo.config.annotation.Service;
import com.niiwoo.civet.user.dao.entity.OrganizationInfo;
import com.niiwoo.civet.user.dto.request.OrganizationInfoReqDTO;
import com.niiwoo.civet.user.dto.response.OrganizationInfoRespDTO;
import com.niiwoo.civet.user.service.OrganizationInfoDubboService;
import com.niiwoo.civet.user.service.local.OrganizationInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Service(version = "1.0.0")
public class OrganizationInfoDubboServiceImpl implements OrganizationInfoDubboService {

    @Autowired
    private OrganizationInfoService organizationInfoService;

    @Override
    public OrganizationInfoRespDTO selectById(String id) {
        OrganizationInfo organizationInfo = organizationInfoService.selectByPrimaryKey(id);
        if(organizationInfo == null) {
            return null;
        }
        OrganizationInfoRespDTO respDTO = new OrganizationInfoRespDTO();
        BeanUtils.copyProperties(organizationInfo, respDTO);
        return respDTO;
    }

    @Override
    public int updateNickName(OrganizationInfoReqDTO reqDTO) {
        OrganizationInfo organizationInfo = new OrganizationInfo();
        organizationInfo.setId(reqDTO.getId());
        organizationInfo.setNickName(reqDTO.getNickName());
        return organizationInfoService.updateByPrimaryKeySelective(organizationInfo);
    }

    @Override
    public int updateHeadImage(OrganizationInfoReqDTO reqDTO) {
        OrganizationInfo organizationInfo = new OrganizationInfo();
        organizationInfo.setId(reqDTO.getId());
        organizationInfo.setHeadImage(reqDTO.getHeadImage());
        return organizationInfoService.updateByPrimaryKeySelective(organizationInfo);
    }
}
